package com.ambow.core.service.impl;

import com.ambow.core.po.DqFrozen;
import com.ambow.core.mapper.DqFrozenMapper;
import com.ambow.core.po.DqInvitation;
import com.ambow.core.service.DqFrozenService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 冻结表 服务实现类
 * </p>
 *
 * @author dq
 * @since 2022-09-05
 */
@Service
public class DqFrozenServiceImpl extends ServiceImpl<DqFrozenMapper, DqFrozen> implements DqFrozenService {

    @Autowired
    private DqFrozenMapper dqFrozenMapper;

    @Override
    public boolean roleIfDongJie(Integer roleId) {
        QueryWrapper<DqFrozen> wrapper = new QueryWrapper();
        wrapper.eq("role_id",roleId);
        //查到了所有冻结记录
        List<DqFrozen> frozenList = dqFrozenMapper.selectList(wrapper);
        System.out.println("冻结"+frozenList);
        boolean index = false;
        if (frozenList.size()<1){
            //无冻结记录
            return false;
        }
        //如果有记录
        else {
            //获取当前时间
            LocalDateTime nowTime= LocalDateTime.now();

            for (DqFrozen frozen : frozenList) {
                System.out.println(frozen.getEndTime()+"   "+nowTime+"    "+nowTime.isAfter(frozen.getEndTime()));
                // 判断当前时间是否在结束时间之后
                if(nowTime.isBefore(frozen.getEndTime())){
                    index =true;
                }
            }
            System.out.println(index);
            return index;
        }
    }

//    @Override
//    public boolean roleIfLaHei(Integer roleId) {
//        return false;
//    }


}
